using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using Rotempco.Core.Logic;

namespace Rotempco.Core.Objects
{
    public class CloningExpression<TSource, TDestination> where TDestination : new()
    {
        private List<TSource> InstanceList;
        private List<Expression<Func<TSource, object>>> IgnoreSourcePropertyMemberList;
        private bool DoSoftClone;

        public CloningExpression(List<TSource> instanceList, bool doSoftClone, List<Expression<Func<TSource, object>>> ignorePropertyMemberList)
        {
            InstanceList = instanceList;
            DoSoftClone = doSoftClone;
            IgnoreSourcePropertyMemberList = ignorePropertyMemberList;
        }

        public CloningExpression<TSource, TDestination> IgnoreSourceProperty(Expression<Func<TSource, object>> sourceMember)
        {
            IgnoreSourcePropertyMemberList.Add(sourceMember);
            return new CloningExpression<TSource, TDestination>(InstanceList, DoSoftClone, IgnoreSourcePropertyMemberList);
        }

        public List<TDestination> ToListX()
        {
            List<TDestination> destination = new List<TDestination>();
            InstanceList.ForEach(i => destination.Add(GenericClonerLogic.Clone<TSource, TDestination>(i, IgnoreSourcePropertyMemberList, DoSoftClone)));
            return destination;
        }

        public TDestination SingleOrDefaultX()
        {
            return GenericClonerLogic.Clone<TSource, TDestination>(InstanceList.SingleOrDefault(), IgnoreSourcePropertyMemberList, DoSoftClone);
        }
    }
}
